﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XiaoYuStock.Core
{
    /// <summary>
    ///  autor：tiny
    ///  time：2018-06-21
    ///  description：api响应记录，只有成功状态，无需返回数据
    /// </summary>
    public class BaseApiResult
    {
        /// <summary>
        /// 构造函数，默认成功
        /// </summary>
        public BaseApiResult()
        {
            this.Code = ApiResultCode.Success;
            this.Message = "OK";
        }

        #region 属性 字段

        /// <summary>
        /// 状态码
        /// </summary>
        public ApiResultCode Code { get; set; }

        /// <summary>
        /// 子状态码
        /// </summary>
        public ApiResultSubCode SubCode { get; set; }

        /// <summary>
        /// 消息提醒
        /// </summary>
        public string Message { get; set; }

        #endregion


        #region 请求失败

        /// <summary>
        ///  autor：tiny
        ///  time：2018-06-20
        ///  description：请求失败
        /// </summary>
        /// <returns></returns>
        public BaseApiResult Error()
        {
            this.Code = ApiResultCode.Error;
            this.Message = "请求超时，请稍后再试！";
            return this;
        }

        /// <summary>
        ///  autor：tiny
        ///  time：2018-06-20
        ///  description：请求失败
        /// </summary>
        /// <param name="msg">错误信息</param>
        /// <returns></returns>
        public BaseApiResult Error(string msg)
        {
            this.Code = ApiResultCode.Error;
            this.Message = msg;
            return this;
        }

        /// <summary>
        ///  autor：tiny
        ///  time：2018-06-20
        ///  description：异常
        /// </summary>
        /// <returns></returns>
        public BaseApiResult Exception()
        {
            this.Code = ApiResultCode.Exception;
            this.Message = "请求超时，请稍后再试！";
            return this;
        }

        /// <summary>
        ///  autor：tiny
        ///  time：2018-06-20
        ///  description：请求失败
        /// </summary>
        /// <param name="subCode">子状态码</param>
        /// <returns></returns>
        public BaseApiResult Error(ApiResultSubCode subCode)
        {
            this.Code = ApiResultCode.Error;
            this.SubCode = subCode;
            this.Message = "请求超时，请稍后再试！";
            return this;
        }

        /// <summary>
        ///  autor：tiny
        ///  time：2018-06-20
        ///  description：请求失败
        /// </summary>
        /// <param name="subCode">子状态码</param>
        /// <param name="msg">错误提醒消息</param>
        /// <returns></returns>
        public BaseApiResult Error(ApiResultSubCode subCode, string msg)
        {
            this.Code = ApiResultCode.Error;
            this.SubCode = subCode;
            this.Message = msg;
            return this;
        }

        #endregion


        #region 请求成功

        /// <summary>
        ///  autor：tiny
        ///  time：2018-06-20
        ///  description：请求成功
        /// </summary>
        /// <returns></returns>
        public BaseApiResult Success()
        {
            this.Code = ApiResultCode.Success;
            this.Message = "ok";
            return this;
        }

        /// <summary>
        ///  autor：tiny
        ///  time：2018-06-20
        ///  description：请求成功
        /// </summary>
        /// <param name="subCode">子状态码</param>
        /// <returns></returns>
        public BaseApiResult Success(ApiResultSubCode subCode)
        {
            this.Code = ApiResultCode.Success;
            this.SubCode = subCode;
            this.Message = "ok";
            return this;
        }

        #endregion

    }
}
